const express = require('express');
const router = express.Router();
const { createCar, getCars, getCar, updateCar, deleteCar } = require('../controllers/carController');
const { createCar: createCarValidation, updateCar: updateCarValidation } = require('../middleware/validator/carValidator');
const { validateRequest } = require('../middleware/validator');
const upload = require('../middleware/upload');

// 创建车辆（移除 token 验证）
router.post('/',
    upload.fields([
        { name: 'coverImage', maxCount: 1 },
        { name: 'images', maxCount: 10 }
    ]),
    upload.processFileUrls,
    createCarValidation,
    validateRequest,
    createCar
);

// 获取车辆列表
router.get('/', getCars);

// 获取单个车辆详情
router.get('/:id', getCar);

// 更新车辆信息（移除 token 验证）
router.put('/:id',
    upload.fields([
        { name: 'coverImage', maxCount: 1 },
        { name: 'images', maxCount: 10 }
    ]),
    updateCarValidation,
    validateRequest,
    updateCar
);

// 删除车辆（移除 token 验证）
router.delete('/:id', deleteCar);

module.exports = router; 